package com.tencent.bugly.crashreport.common.strategy;

import android.content.Context;
import com.tencent.bugly.crashreport.biz.b;
import com.tencent.bugly.proguard.ad;
import com.tencent.bugly.proguard.ae;
import com.tencent.bugly.proguard.ag;
import com.tencent.bugly.proguard.am;
import com.tencent.bugly.proguard.an;
import com.tencent.bugly.proguard.aq;
import com.tencent.bugly.proguard.bk;
import java.util.List;
import java.util.Map;

/* compiled from: BUGLY */
/* loaded from: classes.dex */
public class a {
    public static int a = 1000;
    public static long b = 259200000;
    private static a c;
    private static String i;
    private final List<com.tencent.bugly.a> d;
    private Context h;
    private StrategyBean g = null;
    private final StrategyBean f = new StrategyBean();
    private final am e = am.a();

    protected a(Context context, List<com.tencent.bugly.a> list) {
        this.h = context;
        this.d = list;
    }

    public static synchronized a a(Context context, List<com.tencent.bugly.a> list) {
        a aVar;
        synchronized (a.class) {
            if (c == null) {
                c = new a(context, list);
            }
            aVar = c;
        }
        return aVar;
    }

    public void a(long j) {
        this.e.a(new Thread() { // from class: com.tencent.bugly.crashreport.common.strategy.a.1
            @Override // java.lang.Thread, java.lang.Runnable
            public void run() {
                try {
                    Map<String, byte[]> a2 = ae.a().a(a.a, (ad) null, true);
                    if (a2 != null) {
                        byte[] bArr = a2.get("device");
                        byte[] bArr2 = a2.get("gateway");
                        if (bArr != null) {
                            com.tencent.bugly.crashreport.common.info.a.a(a.this.h).e(new String(bArr));
                        }
                        if (bArr2 != null) {
                            com.tencent.bugly.crashreport.common.info.a.a(a.this.h).d(new String(bArr2));
                        }
                    }
                    a.this.g = a.this.d();
                    if (a.this.g != null && !aq.a(a.i) && aq.c(a.i)) {
                        a.this.g.r = a.i;
                        a.this.g.s = a.i;
                    }
                } catch (Throwable th) {
                    if (!an.a(th)) {
                        th.printStackTrace();
                    }
                }
                a aVar = a.this;
                aVar.a(aVar.g, false);
            }
        }, j);
    }

    public static synchronized a a() {
        a aVar;
        synchronized (a.class) {
            aVar = c;
        }
        return aVar;
    }

    public synchronized boolean b() {
        return this.g != null;
    }

    public StrategyBean c() {
        StrategyBean strategyBean = this.g;
        return strategyBean != null ? strategyBean : this.f;
    }

    protected void a(StrategyBean strategyBean, boolean z) {
        an.c("[Strategy] Notify %s", b.class.getName());
        b.a(strategyBean, z);
        for (com.tencent.bugly.a aVar : this.d) {
            try {
                an.c("[Strategy] Notify %s", aVar.getClass().getName());
                aVar.onServerStrategyChanged(strategyBean);
            } catch (Throwable th) {
                if (!an.a(th)) {
                    th.printStackTrace();
                }
            }
        }
    }

    public static void a(String str) {
        if (aq.a(str) || !aq.c(str)) {
            an.d("URL user set is invalid.", new Object[0]);
        } else {
            i = str;
        }
    }

    public void a(bk bkVar) {
        if (bkVar == null) {
            return;
        }
        if (this.g == null || bkVar.h != this.g.p) {
            StrategyBean strategyBean = new StrategyBean();
            strategyBean.g = bkVar.a;
            strategyBean.i = bkVar.c;
            strategyBean.h = bkVar.b;
            if (aq.a(i) || !aq.c(i)) {
                if (aq.c(bkVar.d)) {
                    an.c("[Strategy] Upload url changes to %s", bkVar.d);
                    strategyBean.r = bkVar.d;
                }
                if (aq.c(bkVar.e)) {
                    an.c("[Strategy] Exception upload url changes to %s", bkVar.e);
                    strategyBean.s = bkVar.e;
                }
            }
            if (bkVar.f != null && !aq.a(bkVar.f.a)) {
                strategyBean.u = bkVar.f.a;
            }
            if (bkVar.h != 0) {
                strategyBean.p = bkVar.h;
            }
            if (bkVar.g != null && bkVar.g.size() > 0) {
                strategyBean.v = bkVar.g;
                String str = bkVar.g.get("B11");
                if (str != null && str.equals("1")) {
                    strategyBean.j = true;
                } else {
                    strategyBean.j = false;
                }
                String str2 = bkVar.g.get("B3");
                if (str2 != null) {
                    strategyBean.y = Long.valueOf(str2).longValue();
                }
                strategyBean.q = bkVar.l;
                strategyBean.x = bkVar.l;
                String str3 = bkVar.g.get("B27");
                if (str3 != null && str3.length() > 0) {
                    try {
                        int parseInt = Integer.parseInt(str3);
                        if (parseInt > 0) {
                            strategyBean.w = parseInt;
                        }
                    } catch (Exception e) {
                        if (!an.a(e)) {
                            e.printStackTrace();
                        }
                    }
                }
                String str4 = bkVar.g.get("B25");
                if (str4 != null && str4.equals("1")) {
                    strategyBean.l = true;
                } else {
                    strategyBean.l = false;
                }
            }
            an.a("[Strategy] enableCrashReport:%b, enableQuery:%b, enableUserInfo:%b, enableAnr:%b, enableBlock:%b, enableSession:%b, enableSessionTimer:%b, sessionOverTime:%d, enableCocos:%b, strategyLastUpdateTime:%d", Boolean.valueOf(strategyBean.g), Boolean.valueOf(strategyBean.i), Boolean.valueOf(strategyBean.h), Boolean.valueOf(strategyBean.j), Boolean.valueOf(strategyBean.k), Boolean.valueOf(strategyBean.n), Boolean.valueOf(strategyBean.o), Long.valueOf(strategyBean.q), Boolean.valueOf(strategyBean.l), Long.valueOf(strategyBean.p));
            this.g = strategyBean;
            ae.a().b(2);
            ag agVar = new ag();
            agVar.b = 2;
            agVar.a = strategyBean.e;
            agVar.e = strategyBean.f;
            agVar.g = aq.a(strategyBean);
            ae.a().a(agVar);
            a(strategyBean, true);
        }
    }

    public StrategyBean d() {
        List<ag> a2 = ae.a().a(2);
        if (a2 == null || a2.size() <= 0) {
            return null;
        }
        ag agVar = a2.get(0);
        if (agVar.g != null) {
            return (StrategyBean) aq.a(agVar.g, StrategyBean.CREATOR);
        }
        return null;
    }
}
